package cn.xinfei.xdecision.common.service.datax.datamanage.v2.impl;

import cn.xinfei.xdecision.common.dao.datax.datamanage.v2.VariableScriptMapper;
import cn.xinfei.xdecision.common.model.datax.datamanage.v2.VariableParam;
import cn.xinfei.xdecision.common.model.datax.datamanage.v2.VariableScript;
import cn.xinfei.xdecision.common.service.datax.datamanage.v2.VariableScriptService;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;


@Service
public class VariableScriptServiceImpl extends ServiceImpl<VariableScriptMapper, VariableScript> implements VariableScriptService {


    @Resource
    VariableScriptMapper variableScriptMapper;

    @Override
    public String findScriptByVariableCode(String varCode) {
        return variableScriptMapper.findScriptByVariableCode(varCode);
    }

    @Override
    public List<String> findScriptsByVariableCodes(List<String> varCodes) {
        return variableScriptMapper.findScriptsByVariableCodes(varCodes);
    }

    @Override
    public List<VariableScript> findAllScripts() {
        return new LambdaQueryChainWrapper<>(variableScriptMapper)
                .select(VariableScript::getVarCode, VariableScript::getScriptContent)
                .eq(VariableScript::getScriptType, 2)
                .eq(VariableScript::getStatus, 1)
                .list();
    }

    @Override
    public Map<String, Map<String,String>> findVarCodeAndScriptByVarCodes(Collection<String> varCodes) {
        if (CollectionUtils.isEmpty(varCodes)) {
            return Collections.emptyMap();
        }
        return variableScriptMapper.findVarCodeAndScriptByVarCodes(varCodes);
    }
}
